package cn.xinfei.xdecision.data.core.schduler;


import org.springframework.scheduling.config.Task;

import javax.annotation.Nullable;
import java.util.concurrent.ScheduledFuture;

public final class CustomSchduledTask {
    private final Task task;

    @Nullable
    volatile ScheduledFuture<?> future;

    public CustomSchduledTask(Task task) {
        this.task = task;
    }

    public Task getTask() {
        return task;
    }

    public void cancel() {
        cancel(true);
    }

    public void cancel(boolean mayInterruptIfRunning) {
        ScheduledFuture<?> future = this.future;
        if (null != future) {
            future.cancel(mayInterruptIfRunning);
        }
    }

    @Override
    public String toString() {
        return this.task.toString();
    }
}
